import { _getAllDevice } from '@/api/mixins'
import { _getTop } from '@/views/house/deviceManage/src/store'

export default {
  data() {
    return {
      deviceList: [],
      defaultProps: {
        children: "children",
        label: "name"
      },
      topList: []
    }
  },
  methods: {
    async getAllDevice() {
      const { success, message, data } = await _getAllDevice()
      if (success) {
        this.deviceList = data
      } else {
        this.$message({ type: 'error', message })
      }
    },
    async mixinOpen() {
      await this.open()
      if (this.opId) {
        this.$refs.tree.setCheckedKeys(this.postData.deviceIds.split(',').map(item => +item).filter(item => !this.topList.includes(item)))
      }
    },
    async initTop() {
      const { data, success, message } = await _getTop()
      this.topList = []
      if (success) {
        this.topList = data.map(item => item.id)
      } else {
        this.$message({ type: 'error', message })
      }
    }
  },
  mounted() {
    this.getAllDevice()
    this.initTop()
  }
}
